using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using UwinEducation.API.Attributes;
using UwinEducation.Application.Common.Interfaces;
using UwinEducation.Application.Dtos;
using UwinEducation.Shared.Models;

namespace UwinEducation.API.Controllers
{
    /// <summary>
    /// 教师课表管理控制器
    /// </summary>
    [Authorize]
    //[RequirePermission("teacher.course")] // 指定所需的权限
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class TeacherScheduleController : ControllerBase
    {
        private readonly ITeacherScheduleService _teacherScheduleService;

        public TeacherScheduleController(ITeacherScheduleService teacherScheduleService)
        {
            _teacherScheduleService = teacherScheduleService;
        }

        /// <summary>
        /// 获取教师课表分页列表
        /// </summary>
        [HttpPost]
        public async Task<ApiResponse<PagedResult<TeacherScheduleDto>>> GetPagedList([FromBody] TeacherSchedulePageRequest request)
        {
            var result = await _teacherScheduleService.GetPagedListAsync(request);
            return ApiResponse<PagedResult<TeacherScheduleDto>>.Ok(result);
        }

        /// <summary>
        /// 老师排课日历数据查询
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResponse<PagedResult<TeacherScheduleDto>>>  GetCalendarList([FromBody] TeacherSchedulePageRequest request)
        {
           var result = await _teacherScheduleService.GetCalendarListAsync(request);
            return ApiResponse<PagedResult<TeacherScheduleDto>>.Ok(result);
        }


        /// <summary>
        /// 获取教师课表详情
        /// </summary>
        [HttpPost]
        public async Task<ApiResponse<TeacherScheduleDto>> GetById([FromBody] IdRequest request)
        {
            var result = await _teacherScheduleService.GetByIdAsync(request.Id);
            return ApiResponse<TeacherScheduleDto>.Ok(result);
        }

        /// <summary>
        /// 创建教师课表
        /// </summary>
        [HttpPost]
        [RequirePermission("teacher.course")] // 指定所需的权限
        public async Task<ApiResponse<List<TeacherScheduleDto>>> Create([FromBody] BatchCreateTeacherScheduleDto input)
        {
            var result = await _teacherScheduleService.CreateAsync(input);
            return ApiResponse<List<TeacherScheduleDto>>.Ok(result);
            
        }

        /// <summary>
        /// 更新教师课表
        /// </summary>
        [HttpPost]
        [RequirePermission("teacher.course")] // 指定所需的权限
        public async Task<ApiResponse<TeacherScheduleDto>> Update([FromBody] UpdateTeacherScheduleDto input)
        {
            var result = await _teacherScheduleService.UpdateAsync(input);
            return ApiResponse<TeacherScheduleDto>.Ok(result);
        }

        /// <summary>
        /// 更新教师课表详情
        /// </summary>
        [HttpPost]
        [RequirePermission("teacher.course")] // 指定所需的权限
        public async Task<ApiResponse<TeacherScheduleDto>> UpdateDetails([FromBody] UpdateTeacherScheduleDetailsDto input)
        {
            var result = await _teacherScheduleService.UpdateDetailsAsync(input);
            return ApiResponse<TeacherScheduleDto>.Ok(result);
        }

        /// <summary>
        /// 删除教师课表
        /// </summary>
        [HttpPost]
        [RequirePermission("teacher.course")] // 指定所需的权限
        public async Task<ApiResponse<object>> Delete([FromBody] IdRequest request)
        {
            await _teacherScheduleService.DeleteAsync(request.Id);
            return ApiResponse<object>.Ok(new object());
        }

        /// <summary>
        /// 批量删除教师课表详情
        /// </summary>
        [HttpPost]
        [RequirePermission("teacher.course")] // 指定所需的权限
        public async Task<ApiResponse<object>> DeleteDetails([FromBody] List<Guid> ids)
        {
            await _teacherScheduleService.DeleteDetailsAsync(ids);
            return ApiResponse<object>.Ok(new object());
        }

        /// <summary>
        /// 获取教师的课表列表
        /// </summary>
        [HttpPost]
        public async Task<ApiResponse<List<TeacherScheduleDto>>> GetByTeacherId([FromBody] IdRequest request)
        {
            var result = await _teacherScheduleService.GetByTeacherIdAsync(request.Id);
            return ApiResponse<List<TeacherScheduleDto>>.Ok(result);
        }

        /// <summary>
        /// 获取课程的课表列表
        /// </summary>
        [HttpPost]
        public async Task<ApiResponse<List<TeacherScheduleDto>>> GetByCourseId([FromBody] IdRequest request)
        {
            var result = await _teacherScheduleService.GetByCourseIdAsync(request.Id);
            return ApiResponse<List<TeacherScheduleDto>>.Ok(result);
        }

        /// <summary>
        /// 获取教师的课表统计列表
        /// </summary>
        [HttpPost]
        public async Task<ApiResponse<PagedResult<TeacherScheduleDto>>> GetStatisticsPagedList([FromBody] TeacherScheduleStatisticsPageRequest request)
        {
            var result = await _teacherScheduleService.GetStatisticsPagedListAsync(request);
            return ApiResponse<PagedResult<TeacherScheduleDto>>.Ok(result);
        }

        /// <summary>
        /// 创建教师课表详情
        /// </summary>
        [HttpPost]
        [RequirePermission("teacher.course")] // 指定所需的权限
        public async Task<ApiResponse<TeacherScheduleDto>> CreateDetails([FromBody] CreateTeacherScheduleDetailsDto input)
        {
            var result = await _teacherScheduleService.CreateDetailsAsync(input);
            return ApiResponse<TeacherScheduleDto>.Ok(result);
        }

        /// <summary>
        /// 获取教师课表详情分页列表
        /// </summary>
        [HttpPost]
        public async Task<ApiResponse<PagedResult<TeacherScheduleDetailsDto>>> GetPagedDetailsList([FromBody] TeacherSchedulePageRequest request)
        {
            var result = await _teacherScheduleService.GetPagedDetailsListAsync(request);
            return ApiResponse<PagedResult<TeacherScheduleDetailsDto>>.Ok(result);
        }



    }
} 